
public class SimpleNotepad implements INotepad
{
	Page[] pages;
	int numberOfPages;

	public SimpleNotepad(int pages) 
	{
		this.numberOfPages = pages;
		this.pages = new Page[numberOfPages];
		for(int i = 0; i < numberOfPages; i++)
		{
			this.pages[i] = new Page(String.valueOf(i));
		}
	}

	@Override
	public void addText(String text, int pageNumber) 
	{
		if(validatePageNumber(pageNumber))
			pages[pageNumber].addText(text);
	}

	@Override
	public void setText(String text, int pageNumber) 
	{	
		if(validatePageNumber(pageNumber))
		{
			pages[pageNumber].deleteText();
			pages[pageNumber].addText(text);
		}	
	}

	@Override
	public void deleteText(int pageNumber) 
	{
		if(validatePageNumber(pageNumber))
			pages[pageNumber].deleteText();	
	}

	@Override
	public void viewNotePad() 
	{
		for(int i = 0; i < numberOfPages; i++)
			System.out.println(pages[i].viewPage());
	}
	
	private boolean validatePageNumber(int pageNumber)
	{
		if(pageNumber < 0 || numberOfPages < pageNumber)
		{
			System.out.println("Invalid page " + pageNumber + ". Must be smaller than " + numberOfPages);
			return false;
		}
		else
			return true;
		
	}
}
